﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BT_BieuThuc_Nhom13.Expressions
{
    public class ConstExpr : Expression
    {
        double value;
        public static ConstExpr ZERO;
        private ConstExpr(double _value)
        {
            value = _value;
        }

        public static Expression CreateObject(double _value)
        {
            if (_value == 0)
            {
                if (ZERO == null)
                {
                    ZERO = new ConstExpr(0);
                }

                return ZERO;
            }

            return new ConstExpr(_value);
        }

        public override double Evaluate(double x)
        {
            return value;
        }

        protected override Expression CreateDerive()
        {
            return new ConstExpr(0);
        }

        public override string ToString()
        {
            return value.ToString();
        }
    }
}
